package com.shilan.administrator.qintfm;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;

import com.shilan.administrator.qintfm.service.PlayService;

/**
 * Created by dllo on 16/1/15.
 */
public abstract class BaseActivity extends AppCompatActivity {

    //public PlayService playService;

    private boolean isBound = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

//    private ServiceConnection connection = new ServiceConnection() {
//        @Override
//        public void onServiceConnected(ComponentName name, IBinder service) {
//            PlayService.PlayBinder playBinder = (PlayService.PlayBinder) service;
//            playService = playBinder.getPlayService();
//            playService.setMusicUpdateListener(musicUpdateListener);
//            musicUpdateListener.onChange(playService.getCurrentPosition());
//        }
//
//        @Override
//        public void onServiceDisconnected(ComponentName name) {
//            playService = null;
//            isBound = false;
//        }
//    };

    public PlayService.MusicUpdateListener musicUpdateListener = new PlayService.MusicUpdateListener() {
        @Override
        public void onPublish(int progress) {
            publish(progress);
        }

        @Override
        public void onChange(int position) {
            change(position);
        }
    };

    public abstract void publish(int progress);
    public abstract void change(int position);


//    //绑定服务
//    public void bindPlayService() {
//        if (!isBound) {
//            Intent intent = new Intent(this, PlayService.class);
//            bindService(intent, connection, Context.BIND_AUTO_CREATE);
//            isBound = true;
//        }
//    }
//
//    //解除绑定服务
//    public void unbindPlayService() {
//        if (isBound) {
//            unbindService(connection);
//            isBound = false;
//        }
//    }
}
